﻿using Base.Infrastructure.Dto.Request.TeaCher;
using Base.Infrastructure.Dto.Response;
using Base.Infrastructure.EFCore.MySql;
using Base.Infrastructure.IOC;
using Base.Infrastructure.Tools;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Base.Service.Instance
{
    public class TeaCherService : BaseService, Base.Service.Interface.ITeaCherService
    {
        private readonly TeaCherIOC _teaCherIOC;

        public TeaCherService(TeaCherIOC teaCherIOC, IConfiguration configuration)
        {
            _teaCherIOC = teaCherIOC;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="teaCher"></param>
        /// <returns></returns>
        private bool AddTeaCher(TeaCher teaCher)
        {
            _teaCherIOC._teaCherService.Add(teaCher);
            return _teaCherIOC._teaCherService.SaveChanges() > 0;
        }

        /// <summary>
        /// 新增职员
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public ApiResult AddTeaCher(TeaCherRequestDto dto)
        {
            //生成随机码
            string Letters = "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,H,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
            var array = Letters.Split(",");
            var random = new Random();
            string randomcode = "";
            for (int i = 0; i < 5; i++)
            {
                randomcode += array[random.Next(array.Length)];
            }

            string tcid = Config.GUID();
            this.AddTeaCher(new TeaCher
            {
               Tcid= tcid,
                Tcaccoun=dto.Tcaccoun,
                Tccode=null,
                Tcname=dto.Tcname,
                Tcdesignation=dto.Tcdesignation,
                TcopenId=dto.TcopenId,
                Verification= randomcode
            });
            return GetResult(1, "操作成功");
        }
    }
}
